<%--
  Created by IntelliJ IDEA.
  User: 19416
  Date: 2022-11-07
  Time: 8:43
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath }/statics/layui/css/layui.css" media="all">
</head>
<body>
<div>
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">供货商名称：</label>
                <div class="layui-input-block">
                    <input class="layui-input" name="supName" id="supName" autocomplete="off">
                </div>
            </div>


            <div class="layui-inline">
                <div class="layui-input-block">
                    <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">搜索</button>
                </div>
            </div>
        </div>
    </form>
</div>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="add">新增</button>
    </div>
</script>
<table id="demo" lay-filter="test"></table>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit" >编辑</a>
    <a class="layui-btn  layui-btn-normal layui-btn-xs" lay-event="view">查看</a>
    <a class="layui-btn  layui-btn-normal layui-btn-xs" lay-event="view2">查看</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
<%--    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="add">添加</a>--%>
</script>

<script src="${pageContext.request.contextPath }/statics/layui/layui.js" charset="utf-8"></script>
<script>
    layui.use(['table','form'], function(){
        var table = layui.table;
        var form = layui.form;
        var $ = layui.$;

        //第一个实例
        var tableIns = table.render({
            elem: '#demo'
            ,height: 530
            ,toolbar:'#toolbarDemo'
            ,url: '${pageContext.request.contextPath}/supplier/supplierList' //数据接口
            ,page: true //开启分页
            ,cols: [[ //表头
                {field:'id', width:170, title: 'id'}
                ,{field:'supCode', width:170, title: '供货商编号'}
                ,{field:'supName', width:170, title: '供货商名称'}
                ,{field:'supContact', width:170, title: '供货商联系人'}
                ,{field:'supPhone', width:170, title: '联系电话'}
                ,{field:'supAddress', width:170, title: '供货商地址'}
                ,{field:'idpicpath', width:135, title: '证件照'}
                ,{fixed: 'right', title:'操作', width: 200, minWidth: 125, toolbar: '#barDemo'}
                // ,{field:'phone', width:80, title: '电话'}
            ]]
        });

        //监听提交
        form.on('submit(demo1)', function(data){
            console.log(data.field)
            //这里以搜索为例
            tableIns.reload({
                where: { //设定异步数据接口的额外参数，任意设
                    supName: data.field.supName//…
                }
                ,page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
            return false;
        });


        // 工具栏事件
        table.on('toolbar(test)', function(obj){
            if (obj.event ==  'add'){}
            switch(obj.event){
                case 'add':
                    window.open('toAdd')
                    break;
            };
        });



        //触发单元格工具事件
        table.on('tool(test)', function(obj) { // 双击 toolDouble
            var data = obj.data;
            console.log(data)
            if (obj.event === 'del') {
                layer.confirm('真的删除行么', function (index) {
                    $.get('delete/' + data.id, function (data) {
                        console.log(data)
                        //关闭提示
                        layer.close(index);
                        if (data === '1') {
                            location.reload();
                        } else {
                            alert('删除失败')
                        }
                    })
                });
            } else if (obj.event === 'edit') {
                window.open("toupdate/"+data.id)
                <%--layer.open({--%>
                <%--    title: '编辑',--%>
                <%--    type: 1,--%>
                <%--    area: ['80%', '80%'],--%>
                <%--    content: `<%@ include file="../update.jsp"%>`--%>

                <%--});--%>
            } else if (obj.event == "view") {
                console.log(obj);
                window.open('supplierView2/' + data.id)
            }

        })


    });
</script>

</body>
</html>
